import time
from google.appengine.ext import db

class Server(db.Model):
    id = db.StringProperty()
    address = db.StringProperty()
    port = db.IntegerProperty()
    name = db.StringProperty(indexed=False)
    expiration = db.DateTimeProperty()
    version = db.StringProperty(indexed=False)
    cookie = db.StringProperty()
    start = db.DateTimeProperty(indexed=False)
    num_users = db.IntegerProperty(indexed=False)

    def start_time(self):
        return int(time.mktime(self.start.timetuple()))

class Room(db.Model):
    id = db.IntegerProperty(indexed=False)
    name = db.StringProperty(indexed=False)
    num_users = db.IntegerProperty(indexed=False)
    pwd = db.BooleanProperty(indexed=False)
    server = db.ReferenceProperty(Server, collection_name="rooms")

class Player(db.Model):
    name = db.StringProperty(indexed=False)
    room = db.ReferenceProperty(Room, collection_name="players")

class Note(db.Model):
    version = db.StringProperty()
    html = db.TextProperty()
    outdated = db.BooleanProperty(default=False)